package com.yanqu.road.server.cmd.activity.fivehero;

import com.yanqu.road.entity.activity.fivehero.FiveHeroConfig;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.entity.player.UserBagItem;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.FiveHeroProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.BagModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.fivehero.FiveHeroMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.property.Property;

import java.util.ArrayList;
import java.util.List;


@Cmd(code = GameProtocol.S_FIVEHERO_CHECK_USER_ONLINE, desc = "")
public class CrossFiveHeroCheckUserOnlineCmd extends AbstractCommand {

    private FiveHeroProto.FiveHeroCheckUserOnlineMsg reqMsg;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        reqMsg = FiveHeroProto.FiveHeroCheckUserOnlineMsg.parseFrom(packet.getBytes());
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        FiveHeroConfig config = FiveHeroMgr.getConfig();
        if (config == null || !ActivityMgr.activityInShowTime(config.getActivityInfo())) {
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }
        List<Long> offLineUserIdList = new ArrayList<>();
        for(long userId : reqMsg.getUserIdList()){
            GamePlayer gamePlayer = GamePlayerMgr.getOnlinePlayer(userId);
            if(gamePlayer == null){
                offLineUserIdList.add(userId);
            }
        }
        if(offLineUserIdList.size() > 0){
            FiveHeroProto.CrossFiveHeroUserOffOnlineMsg.Builder offMsg = FiveHeroProto.CrossFiveHeroUserOffOnlineMsg.newBuilder();
            offMsg.setActivityId(reqMsg.getActivityId());
            offMsg.setGroupId(reqMsg.getGroupId());
            offMsg.addAllUserId(offLineUserIdList);
            GamePlayerMgr.sendUnionActivityGroupPacket(CrossProtocol.C2_CROSS_FIVE_HERO_OFFLINE, offMsg,0,reqMsg.getActivityId(),reqMsg.getGroupId());

        }
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret == 0) {
            return;
        }
    }
}
